/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JEVEMeCharacterPanel.java
 *
 * Created on Jun 16, 2011, 9:19:00 AM
 */
package jeveme;

import java.awt.Color;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Image;
import java.io.BufferedInputStream;
import java.net.MalformedURLException;
import javax.swing.ImageIcon;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import javax.imageio.ImageIO;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.ToolTipManager;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeCellRenderer;
import javax.swing.tree.TreeNode;
import jeveme.datacontainers.EVECharacter;
import jeveme.datacontainers.EVEMasterSkillSheet;
import jeveme.datacontainers.EVESkill;
import jeveme.datacontainers.EVESkillGroup;
import jeveme.helpers.OperatingSystem;
import org.jdesktop.application.Action;

/**
 *
 * @author ruizr
 */
public class JEVEMeCharacterPanel extends javax.swing.JPanel {

    private EVECharacter m_character;
    
    /** Creates new form JEVEMeCharacterPanel */
    public JEVEMeCharacterPanel(EVECharacter character) {
        m_character = character;
        skillsRenderer = new SkillCellRenderer();
        initComponents();
        //Enable Tooltips for the skill tree.
        ToolTipManager.sharedInstance().registerComponent(m_skillTree);
        
        //Update the character Panel.
        updatePanel();
    }
    
    private void updatePanel() {
        
        //Character Portrait
        characterPortraitLabel.setIcon(m_character.getCharacterPortrait());
        
        //Character Name
        characterNameLabel.setText(m_character.getCharacterName());
        
        //Corporation
        characterCorporationLabel.setText("Corporation: " + m_character.getCorporationName());
        
        //Birthday
        characterBirthdayLabel.setText("Birthday: " + m_character.getDateOfBirth());
        
        //Bloodline
        characterBloodlineLabel.setText(m_character.getGender() + " - " + m_character.getRace() + " - " + m_character.getBloodLine() + " - " + m_character.getAncestry());
    
        //Balance
        java.text.DecimalFormatSymbols symbols = new java.text.DecimalFormatSymbols();
        symbols.setGroupingSeparator(',');
        java.text.DecimalFormat formatter = new java.text.DecimalFormat("###,###.00",symbols);
        String formatted_balance=formatter.format(new java.math.BigDecimal(m_character.getBalance()));
        characterBalanceLabel.setText("Balance: " + formatted_balance);
        
        //Clone Grade
        characterCloneGradeLabel.setText(m_character.getCloneName());
        
        //Clone Skill Points
        characterCloneLimitLabel.setText("Clone Limit: " + m_character.getCloneSkillPoints());
        
        //Intelligence
        characterIntelligenceLabel.setText("Intelligence: " + m_character.getIntelligence()); 
        //Memory
        characterMemoryLabel.setText("Memory: " + m_character.getMemory());
        //Charisma
        characterCharismaLabel.setText("Charisma: " + m_character.getCharisma());
        //Perception
        characterPerceptionLabel.setText("Perception: " + m_character.getPerception());
        //Willpower
        characterWillpowerLabel.setText("Willpower: " + m_character.getWillpower());
        
        //Known Skills
        characterKnownSkillsLabel.setText("Known Skills: " + m_character.getTotalSkillsKnown());
        //Skills at Level V
        characterSkillsVLabel.setText("Skills at Level V: " + m_character.getTotalSkillsAtLevelFive());
        //Total SP
        characterTotalSPLabel.setText("Total SP: " + m_character.getTotalSkillPoints());
        
        //Character Skills
        ArrayList<EVESkill> characterSkills = m_character.getAllSkills();
        EVEMasterSkillSheet emss = EVEMasterSkillSheet.getInstance();
        //Create the tree and root node
        m_skillTree.removeAll();
        skillsRenderer = new SkillCellRenderer();
        m_skillTree.setCellRenderer(skillsRenderer);
        DefaultMutableTreeNode topNode = new DefaultMutableTreeNode(m_character.getCharacterName());
        DefaultMutableTreeNode skillsCategory = null;
        DefaultMutableTreeNode skillNode = null;
        
        
        ArrayList<EVESkillGroup> skillGroups = emss.getSkillGroups();
        int counter = 0;
        for(int i=0; i<skillGroups.size(); i++) {
            EVESkillGroup esg = skillGroups.get(i);
            if(esg.getSkillGroupName().equals("Fake Skills")) {
                continue;
            }            

            skillsCategory = new DefaultMutableTreeNode(esg);
            
            ArrayList<EVESkill> skills = m_character.getSkillsByGroupID(esg.getSkillGroupID());
            for(counter=0; counter < skills.size(); counter++) {
                EVESkill es = skills.get(counter);
                skillNode = new DefaultMutableTreeNode(es);
                skillsCategory.add(skillNode);
            }
            topNode.add(skillsCategory);
        }
        
        DefaultTreeModel tm = new DefaultTreeModel(topNode);
        m_skillTree.setModel(tm);

        m_skillTree.validate();
        
    }
    
    
    
    public void didRequestCharacterUpdate() {
        m_character.updateCharacter(true);
    }
    
        
    @Action
    public void didPressUpdatePortraitFromEVEMenuItem() {
        PortraitUpdater pu = new PortraitUpdater();
        new Thread(pu).start();        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        characterPortraitPopupMenu = new javax.swing.JPopupMenu();
        updatePortraitMenuItem = new javax.swing.JMenuItem();
        topPanel = new javax.swing.JPanel();
        characterPortraitLabel = new javax.swing.JLabel();
        characterNameLabel = new javax.swing.JLabel();
        characterBloodlineLabel = new javax.swing.JLabel();
        characterBirthdayLabel = new javax.swing.JLabel();
        characterCorporationLabel = new javax.swing.JLabel();
        characterBalanceLabel = new javax.swing.JLabel();
        characterIntelligenceLabel = new javax.swing.JLabel();
        characterPerceptionLabel = new javax.swing.JLabel();
        characterCharismaLabel = new javax.swing.JLabel();
        characterWillpowerLabel = new javax.swing.JLabel();
        characterMemoryLabel = new javax.swing.JLabel();
        characterKnownSkillsLabel = new javax.swing.JLabel();
        characterSkillsVLabel = new javax.swing.JLabel();
        characterTotalSPLabel = new javax.swing.JLabel();
        characterCloneLimitLabel = new javax.swing.JLabel();
        characterCloneGradeLabel = new javax.swing.JLabel();
        cardSelectorPanel = new javax.swing.JPanel();
        cardPanel = new javax.swing.JPanel();
        skillCard = new javax.swing.JPanel();
        skillCardScroll = new javax.swing.JScrollPane();
        m_skillTree = new javax.swing.JTree();

        characterPortraitPopupMenu.setName("characterPortraitPopupMenu"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(jeveme.JEVEMeApp.class).getContext().getActionMap(JEVEMeCharacterPanel.class, this);
        updatePortraitMenuItem.setAction(actionMap.get("didPressUpdatePortraitFromEVEMenuItem")); // NOI18N
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(jeveme.JEVEMeApp.class).getContext().getResourceMap(JEVEMeCharacterPanel.class);
        updatePortraitMenuItem.setText(resourceMap.getString("updatePortraitMenuItem.text")); // NOI18N
        updatePortraitMenuItem.setName("updatePortraitMenuItem"); // NOI18N
        characterPortraitPopupMenu.add(updatePortraitMenuItem);

        setBackground(resourceMap.getColor("CharacterPanel.background")); // NOI18N
        setName("CharacterPanel"); // NOI18N

        topPanel.setBackground(resourceMap.getColor("topPanel.background")); // NOI18N
        topPanel.setName("topPanel"); // NOI18N
        topPanel.setPreferredSize(new java.awt.Dimension(1155, 240));

        characterPortraitLabel.setText(resourceMap.getString("characterPortraitLabel.text")); // NOI18N
        characterPortraitLabel.setComponentPopupMenu(characterPortraitPopupMenu);
        characterPortraitLabel.setName("characterPortraitLabel"); // NOI18N
        characterPortraitLabel.setPreferredSize(new java.awt.Dimension(128, 128));

        characterNameLabel.setFont(resourceMap.getFont("characterNameLabel.font")); // NOI18N
        characterNameLabel.setText(resourceMap.getString("characterNameLabel.text")); // NOI18N
        characterNameLabel.setName("characterNameLabel"); // NOI18N

        characterBloodlineLabel.setText(resourceMap.getString("characterBloodlineLabel.text")); // NOI18N
        characterBloodlineLabel.setName("characterBloodlineLabel"); // NOI18N

        characterBirthdayLabel.setText(resourceMap.getString("characterBirthdayLabel.text")); // NOI18N
        characterBirthdayLabel.setName("characterBirthdayLabel"); // NOI18N

        characterCorporationLabel.setText(resourceMap.getString("characterCorporationLabel.text")); // NOI18N
        characterCorporationLabel.setName("characterCorporationLabel"); // NOI18N

        characterBalanceLabel.setText(resourceMap.getString("characterBalanceLabel.text")); // NOI18N
        characterBalanceLabel.setName("characterBalanceLabel"); // NOI18N

        characterIntelligenceLabel.setText(resourceMap.getString("characterIntelligenceLabel.text")); // NOI18N
        characterIntelligenceLabel.setName("characterIntelligenceLabel"); // NOI18N

        characterPerceptionLabel.setText(resourceMap.getString("characterPerceptionLabel.text")); // NOI18N
        characterPerceptionLabel.setName("characterPerceptionLabel"); // NOI18N

        characterCharismaLabel.setText(resourceMap.getString("characterCharismaLabel.text")); // NOI18N
        characterCharismaLabel.setName("characterCharismaLabel"); // NOI18N

        characterWillpowerLabel.setText(resourceMap.getString("characterWillpowerLabel.text")); // NOI18N
        characterWillpowerLabel.setName("characterWillpowerLabel"); // NOI18N

        characterMemoryLabel.setText(resourceMap.getString("characterMemoryLabel.text")); // NOI18N
        characterMemoryLabel.setName("characterMemoryLabel"); // NOI18N

        characterKnownSkillsLabel.setText(resourceMap.getString("characterKnownSkillsLabel.text")); // NOI18N
        characterKnownSkillsLabel.setName("characterKnownSkillsLabel"); // NOI18N

        characterSkillsVLabel.setText(resourceMap.getString("characterSkillsVLabel.text")); // NOI18N
        characterSkillsVLabel.setName("characterSkillsVLabel"); // NOI18N

        characterTotalSPLabel.setText(resourceMap.getString("characterTotalSPLabel.text")); // NOI18N
        characterTotalSPLabel.setName("characterTotalSPLabel"); // NOI18N

        characterCloneLimitLabel.setText(resourceMap.getString("characterCloneLimitLabel.text")); // NOI18N
        characterCloneLimitLabel.setName("characterCloneLimitLabel"); // NOI18N

        characterCloneGradeLabel.setText(resourceMap.getString("characterCloneGradeLabel.text")); // NOI18N
        characterCloneGradeLabel.setName("characterCloneGradeLabel"); // NOI18N

        javax.swing.GroupLayout topPanelLayout = new javax.swing.GroupLayout(topPanel);
        topPanel.setLayout(topPanelLayout);
        topPanelLayout.setHorizontalGroup(
            topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(topPanelLayout.createSequentialGroup()
                .addGroup(topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(topPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(characterPortraitLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(characterCorporationLabel)
                            .addComponent(characterBirthdayLabel)
                            .addComponent(characterBloodlineLabel)
                            .addGroup(topPanelLayout.createSequentialGroup()
                                .addGroup(topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(characterBalanceLabel)
                                    .addComponent(characterIntelligenceLabel)
                                    .addComponent(characterPerceptionLabel)
                                    .addGroup(topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(characterWillpowerLabel)
                                        .addComponent(characterCharismaLabel)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 854, Short.MAX_VALUE)
                                .addGroup(topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(characterSkillsVLabel)
                                    .addComponent(characterKnownSkillsLabel)
                                    .addComponent(characterTotalSPLabel)
                                    .addComponent(characterCloneGradeLabel)
                                    .addComponent(characterCloneLimitLabel)))
                            .addComponent(characterMemoryLabel)))
                    .addGroup(topPanelLayout.createSequentialGroup()
                        .addGap(156, 156, 156)
                        .addComponent(characterNameLabel)))
                .addContainerGap())
        );
        topPanelLayout.setVerticalGroup(
            topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(topPanelLayout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addComponent(characterPortraitLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(140, 140, 140))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, topPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, topPanelLayout.createSequentialGroup()
                        .addComponent(characterKnownSkillsLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(characterSkillsVLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(characterTotalSPLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(characterCloneLimitLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(characterCloneGradeLabel)
                        .addGap(46, 46, 46))
                    .addGroup(topPanelLayout.createSequentialGroup()
                        .addComponent(characterNameLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(characterBloodlineLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(characterBirthdayLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(characterCorporationLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(characterBalanceLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(characterIntelligenceLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(characterPerceptionLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(characterCharismaLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(characterWillpowerLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addComponent(characterMemoryLabel)
                .addGap(71, 71, 71))
        );

        cardSelectorPanel.setName("cardSelectorPanel"); // NOI18N

        javax.swing.GroupLayout cardSelectorPanelLayout = new javax.swing.GroupLayout(cardSelectorPanel);
        cardSelectorPanel.setLayout(cardSelectorPanelLayout);
        cardSelectorPanelLayout.setHorizontalGroup(
            cardSelectorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1155, Short.MAX_VALUE)
        );
        cardSelectorPanelLayout.setVerticalGroup(
            cardSelectorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 34, Short.MAX_VALUE)
        );

        cardPanel.setName("cardPanel"); // NOI18N
        cardPanel.setLayout(new java.awt.CardLayout());

        skillCard.setName("skillCard"); // NOI18N

        skillCardScroll.setViewportBorder(javax.swing.BorderFactory.createEtchedBorder());
        skillCardScroll.setAutoscrolls(true);
        skillCardScroll.setMinimumSize(new java.awt.Dimension(1, 1));
        skillCardScroll.setName("skillCardScroll"); // NOI18N

        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("root");
        m_skillTree.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        m_skillTree.setAutoscrolls(true);
        m_skillTree.setMaximumSize(new java.awt.Dimension(58000, 58000));
        m_skillTree.setMinimumSize(new java.awt.Dimension(1, 1));
        m_skillTree.setName("m_skillTree"); // NOI18N
        m_skillTree.setRootVisible(false);
        m_skillTree.setRowHeight(50);
        skillCardScroll.setViewportView(m_skillTree);

        javax.swing.GroupLayout skillCardLayout = new javax.swing.GroupLayout(skillCard);
        skillCard.setLayout(skillCardLayout);
        skillCardLayout.setHorizontalGroup(
            skillCardLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(skillCardScroll, javax.swing.GroupLayout.DEFAULT_SIZE, 1155, Short.MAX_VALUE)
        );
        skillCardLayout.setVerticalGroup(
            skillCardLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(skillCardScroll, javax.swing.GroupLayout.DEFAULT_SIZE, 319, Short.MAX_VALUE)
        );

        cardPanel.add(skillCard, "skillCard");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(topPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(cardSelectorPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(cardPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 1155, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(topPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cardSelectorPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cardPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 319, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(79, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel cardPanel;
    private javax.swing.JPanel cardSelectorPanel;
    private javax.swing.JLabel characterBalanceLabel;
    private javax.swing.JLabel characterBirthdayLabel;
    private javax.swing.JLabel characterBloodlineLabel;
    private javax.swing.JLabel characterCharismaLabel;
    private javax.swing.JLabel characterCloneGradeLabel;
    private javax.swing.JLabel characterCloneLimitLabel;
    private javax.swing.JLabel characterCorporationLabel;
    private javax.swing.JLabel characterIntelligenceLabel;
    private javax.swing.JLabel characterKnownSkillsLabel;
    private javax.swing.JLabel characterMemoryLabel;
    private javax.swing.JLabel characterNameLabel;
    private javax.swing.JLabel characterPerceptionLabel;
    private javax.swing.JLabel characterPortraitLabel;
    private javax.swing.JPopupMenu characterPortraitPopupMenu;
    private javax.swing.JLabel characterSkillsVLabel;
    private javax.swing.JLabel characterTotalSPLabel;
    private javax.swing.JLabel characterWillpowerLabel;
    private javax.swing.JTree m_skillTree;
    private javax.swing.JPanel skillCard;
    private javax.swing.JScrollPane skillCardScroll;
    private javax.swing.JPanel topPanel;
    private javax.swing.JMenuItem updatePortraitMenuItem;
    // End of variables declaration//GEN-END:variables

    TreeCellRenderer skillsRenderer;
    
    /**
     * Class to update portraits through a thread.
     */
    class PortraitUpdater implements Runnable {
        public PortraitUpdater() {
            
        }
        @Override
        public void run() {
            try {
                m_character.updateCharacterPortraitFromEVE();
                characterPortraitLabel.setIcon(m_character.getCharacterPortrait());
            }
            catch(Exception e) {}
        }
    }
    
    class SkillCellRenderer extends JPanel implements TreeCellRenderer {
        
        public SkillCellRenderer() {
            super();
            this.setLayout(new FlowLayout());
        }
        
        @Override
        public Component getTreeCellRendererComponent(JTree tree, Object value,
                                    boolean selected, boolean expanded, boolean leaf, int row,
                                    boolean hasFocus) {
            
            this.setSize(tree.getSize().width, 50);
            DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
            Object userObj =  node.getUserObject();  
            if(userObj instanceof EVESkillGroup) {
                EVESkillGroup esg = (EVESkillGroup) userObj;
                System.out.println("Category: " + esg.getSkillGroupName());
                
                setBackground(Color.DARK_GRAY);
                //Set the tooltip text
                setToolTipText(esg.getSkillGroupName());
                
                JLabel categoryLabel = new JLabel();
                categoryLabel.setText(esg.getSkillGroupName());
                categoryLabel.setForeground(Color.BLACK);
                categoryLabel.setSize(tree.getSize().width,50);
                
                add(categoryLabel);

                return this;
                
            }
            else if(userObj instanceof EVESkill) {
                EVESkill es = (EVESkill) userObj;
                System.out.println("Saw Skill: " + es.getName());
                
                setBackground(Color.WHITE);
                
                //Set the ToolTip text
                setToolTipText(es.getDescription());
                JLabel skillLabel = new JLabel();
                skillLabel.setText(es.getName());                                             
                skillLabel.setForeground(Color.black);
                skillLabel.setBackground(Color.white);
                skillLabel.setSize(tree.getSize().width,50);
                
                add(skillLabel);

                return this;
            }
            else if(userObj instanceof String) {
                JLabel test = new JLabel((String) userObj);
                test.setSize(tree.getSize().width, 50);
                add(test);

                return this;
            }
            repaint();
            return this;
        }
    }

}
